// import axios from '@/utils/request'
var format = require('date-format')

const TYPES = {
  0: '酒代分成',
  1: '管理员分成',
  2: '平台分成',
  3: '负责人分成',
  4: '场所分成',
  5: '资源公司分成',
  6: '队长分成',
  7: '经纪人分成',
  8: '提成',
  9: '补贴',
  10: '工资',
  11: '订台分成',
  12: '服务员分成',
  100: '剩余余额',
  999: '平台手续费'
}
export default {
  OfficerSettleItem: {
    entity: { name: 'SettleItem', prefix: `officer` },
    form: {
      fields: [
        'status',
        'paidTime'
      ]
    },
    list: {
      export: {
        query: {
          '@display': `{
                    'counter' : 'entity.getSettle().getOrderItem().getOrder().getCounter().__toString()',
                    'product' : 'entity.getSettle().getOrderItem().getSpecification().__toString()',
                    'quantity' : 'entity.getSettle().getOrderItem().getQuantity()',
                    'price' : 'entity.getSettle().getOrderItem().getPrice()',
                    'profitType' : '{0: "酒代分成",1: "管理员分成",2: "平台分成",3: "负责人分成",4: "场所分成",5: "资源公司分成",6: "队长分成",7: "经纪人分成",8: "提成",9: "补贴",10: "工资",11: "订台分成",12: "服务员分成",100: "剩余余额",999: "平台手续费"}[entity.getProfitType()]',
                    'amount' : 'entity.getAmount()',
                    'acc': 'entity.getStaff() ? entity.getStaff().__toString() : entity.getUser().__toString()',
                    'settled' : '{0: "未分账",1: "已分账"}[entity.getSettled()]',
                    'createdTime' : 'entity.getCreatedTime().format("Y-m-d H:i:s")'
                }`,
          'limit': 100000000
        },
        label: {
          'counter': '台号',
          'product': '产品',
          'quantity': '数量',
          'price': '总价',
          'profitType': '类型',
          'amount': '分账金额',
          'acc': '分账账号',
          'settled': '分账状态',
          'createdTime': '结算时间'
        }
      },
      disabled_actions: ['new', 'lines', 'edit', 'delete'],
      query: {
        '@order': 'entity.id|DESC',
        '@expands': "['entity.settle.orderItem.order']"
      },
      list_display: [
        'id',
        { property: 'settle.__metadata.orderItem.__metadata.order.__metadata.counter.__toString', label: '台号' },
        { property: 'settle.__metadata.orderItem.__metadata.specification.__toString', label: '产品' },
        { property: 'settle.__metadata.orderItem.__metadata.quantity', label: '数量' },
        { property: 'settle.__metadata.orderItem.__metadata.price', label: '总价' },
        {
          property: 'profitType', label: '类型',
          component: {
            props: ['data'],
            data() {
              return {
                types: TYPES
              }
            },
            render(h) {
              return (
                <span>{this.types[this.data]}</span>
              )
            }
          }
        },
        {
          property: 'amount', label: '分账金额',
          component: {
            props: ['data'],
            render(h) {
              return <p>￥{this.data}</p>
            }
          }
        },
        {
          property: 'acc', label: '分账账号',
          component: {
            props: ['record'],
            render(h) {
              if (this.record.staff) {
                return <span>{this.record.staff.__toString}</span>
              } else {
                return <span>{this.record.user.__toString}</span>
              }
            }
          }
        },
        {
          property: 'settled', label: '分账状态',
          component: {
            props: ['data', 'record'],
            render(h) {
              if (this.data) {
                return <el-tag type='success'>已分账</el-tag>
              } else {
                return <el-tag type='warning'>未分账</el-tag>
              }
            }
          }
        },
        {
          property: 'settle.__metadata.orderItem.__metadata.order.__metadata.createdTime',
          label: '订单创建时间',
          component: {
            props: ['data'],
            data() {
              return { createdTime: format('yyyy-MM-dd hh:mm:ss', new Date(this.data)) }
            },
            render(h) {
              return <span>{ this.createdTime }</span>
            }
          }
        },
        { property: 'createdTime', label: '结算时间' }
      ]
    }
  }
}

